
function adduser(){
	//alert("aa");
	var username = $("input[name='username']").val();
	var password = $("input[name='password']").val();
	var role=$("select[name='role']").val();
	if(username=="" ||username==null||password==""||password==null){
		alert("用户名或者密码不完整！请重新输入！");
		document.getElementById("username").value="";
		document.getElementById("password").value="";
	}else{
		//alert(username+password+role);
		$.post('jsp/account/addAccount.jsp', 'username='+username+'&password='+password+'&role='+role, function(data) {
			//alert("bb");
			json = eval('('+data+')');
			var res = json.result;
			//alert(res);
			if (res == "success") {
				alert("添加用户成功！");
				document.getElementById("username").value="";
				document.getElementById("password").value="";
			}else if(res == "fail"){
				alert("添加用户失败！");
				document.getElementById("username").value="";
				document.getElementById("password").value="";
		    }else if(res =="failp") { 
				alert("该用户已存在！");
				document.getElementById("username").value="";
				document.getElementById("password").value="";
			}
		});
		
	}
	return false;
};

function getnum(){
	var subject=$("select[id='subject1']").val();
	if(subject=="无"){
		
	}else{
		$.post('jsp/worddictionary/getSubjectNum.jsp', 'subject='+subject, function(data) {
			//alert("bb");
			json = eval('('+data+')');
			var from=json.from;
			var end=json.end;
			//alert(res);
			document.getElementById("numrange").value=from+"至"+end;
		});
	}
};

function taskAsign(){
	
	var from=$("input[id='id_begin']").val();
	var end=$("input[id='id_end']").val();
	var compiler=$("input[id='worker']").val();
	//alert(from+end+compiler);
	if(from.length!=8 || end.length!=8 || from>end){
		alert("编号输入错误!");
	}else{
		$.post('jsp/worddictionary/updateCompiler.jsp', 'from='+from+'&end='+end+'&compiler='+compiler, function(data) {
			//alert("bb");
			json = eval('('+data+')');
			var res=json.result;
			if(res=="noaccount"){
				alert("该用户无编撰者账号！请先为其创建账号！");
			}else if(res=="success"){
				alert("任务分配成功！");
				document.getElementById("id_begin").value="";
				document.getElementById("id_end").value="";
				document.getElementById("worker").value="";
			}else if(res=="fail"){
				alert("任务分配失败！请核对分配编号！");
				
			}else{
				alert("部分分配成功！请核对分配编号！");
			}
		});
	}
};

$('#searchbtn').click(function(){
	var subject=$("select[id='subject2']").val();
	//alert(subject);
	$.post('jsp/worddictionary/taskCondition.jsp', 'subject='+subject, function(data) {
		json = eval('('+data+')');
		var unfinished=Number(json.unfinished);
		var finished=Number(json.finished);
		var doubt=Number(json.doubt);
		var pass=Number(json.pass);
		var unpass=Number(json.unpass);
		var uncheck=Number(json.uncheck);
		var total=unfinished+finished+doubt;
		var finishtotal=pass+unpass+uncheck;
		//alert(unfinished+" "+finished+" "+doubt+" "+total);
		//alert(pass+" "+unpass+" "+uncheck);
		$("#process1").css({"width":+(finished/total*100).toFixed(2)+"%"});
		document.getElementById("process1").innerHTML=(finished/total*100).toFixed(2)+"%";
		$("#process2").css({"width":+Math.round(doubt/total*1000)/1000*100+"%"});
		document.getElementById("process2").innerHTML=(doubt/total*100).toFixed(2)+"%";
		$("#process3").css({"width":+Math.round(unfinished/total*1000)/1000*100+"%"});
		document.getElementById("process3").innerHTML=(unfinished/total*100).toFixed(2)+"%";
		
		$("#process4").css({"width":+Math.round(finished/total*1000)/1000*100+"%"});
		document.getElementById("process4").innerHTML=finished+"条";
		$("#process5").css({"width":+Math.round(doubt/total*1000)/1000*100+"%"});
		document.getElementById("process5").innerHTML=doubt+"条";
		$("#process6").css({"width":+Math.round(unfinished/total*1000)/1000*100+"%"});
		document.getElementById("process6").innerHTML=unfinished+"条";
		
		$("#process7").css({"width":+Math.round(pass/finishtotal*1000)/1000*100+"%"});
		document.getElementById("process7").innerHTML=(pass/finishtotal*100).toFixed(2)+"%";
		$("#process8").css({"width":+Math.round(unpass/finishtotal*1000)/1000*100+"%"});
		document.getElementById("process8").innerHTML=(unpass/finishtotal*100).toFixed(2)+"%";
		$("#process9").css({"width":+Math.round(uncheck/finishtotal*1000)/1000*100+"%"});
		document.getElementById("process9").innerHTML=(uncheck/finishtotal*100).toFixed(2)+"%";
		
		$("#process10").css({"width":+Math.round(pass/finishtotal*1000)/1000*100+"%"});
		document.getElementById("process10").innerHTML=pass+"条";
		$("#process11").css({"width":+Math.round(unpass/finishtotal*1000)/1000*100+"%"});
		document.getElementById("process11").innerHTML=unpass+"条";
		$("#process12").css({"width":+Math.round(uncheck/finishtotal*1000)/1000*100+"%"});
		document.getElementById("process12").innerHTML=uncheck+"条";
		
	});
});

$('#searchbtn2').click(function(){
	var subject=$("select[id='subject3']").val();
	var compiler=$("input[id='worker2']").val();
	//alert(subject+";"+compiler);
	if(compiler==null || compiler==""){
		alert("请输入编撰者姓名！");
	}else{
		$.post('jsp/worddictionary/getWordlist.jsp', 'subject='+subject+'&compiler='+compiler, function(data) {
			json = eval('('+data+')');
			var finishedlist=json.finishedlist;//当记录为空的时候返回的是：[],长度为2
			var doubtlist=json.doubtlist;
			var unfinishedlist=json.unfinishedlist;
			var unpass=json.unpass;
			var unchecked=json.unchecked;
			var idcount=0;
			//alert(unchecked);
			
			if(finishedlist.length<=2 && doubtlist.length<=2 && unfinishedlist.length<=2 && unpass.length<=2 && unchecked.length<=2){
				alert("【"+compiler+"】在此学科无任务！");
			}
			
			if(finishedlist.length>2){
				finishedlist=finishedlist.substring(1,finishedlist.length-1);
				var finili =finishedlist.split(",");
				var htmlAppend='';
				//var displaycount=20;//展示20个即可
				//if(finili.length<20){displaycount=finili.length}
				var displaycount=finili.length;
				for(var i=0;i<displaycount;i++){
					htmlAppend=htmlAppend+'&nbsp;&nbsp;&nbsp;<a id=word'+idcount+' style="cursor:pointer" onclick="getDetail(this);">'+finili[i]+'</a>'+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>';
					idcount++;
				}
				$("#finished").html(htmlAppend);
			}
			if(doubtlist.length>2){
				doubtlist=doubtlist.substring(1,doubtlist.length-1);
				var douli =doubtlist.split(",");
				var htmlAppend2='';
				//var displaycount2=20;//展示20个即可
				//if(douli.length<20){displaycount2=douli.length}
				var displaycount2=douli.length;
				for(var i=0;i<displaycount2;i++){
					htmlAppend2=htmlAppend2+'&nbsp;&nbsp;&nbsp;<a id=word'+idcount+' style="cursor:pointer" onclick="getDetail(this);">'+douli[i]+'</a>'+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>';
					idcount++;
				}
				$("#doubt").html(htmlAppend2);
			}
			if(unfinishedlist.length>2){
				unfinishedlist=unfinishedlist.substring(1,unfinishedlist.length-1);
				var unfinili =unfinishedlist.split(",");
				var htmlAppend='';
				//var displaycount=20;//展示20个即可
				//if(unfinili.length<20){displaycount=unfinili.length}
				var displaycount3=unfinili.length;
				for(var i=0;i<displaycount3;i++){
					htmlAppend=htmlAppend+'&nbsp;&nbsp;&nbsp;<a id=word'+idcount+' style="cursor:pointer" onclick="getDetail(this);">'+unfinili[i]+'</a>'+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>';
					idcount++;
				}
				$("#unfinished").html(htmlAppend);
			}
			if(unpass.length>2){
				unpass=unpass.substring(1,unpass.length-1);
				var unpassli =unpass.split(",");
				var htmlAppend='';
				//var displaycount=20;//展示20个即可
				//if(unpassli.length<20){displaycount=unpassli.length}
				var displaycount4=unpassli.length;
				for(var i=0;i<displaycount4;i++){
					htmlAppend=htmlAppend+'&nbsp;&nbsp;&nbsp;<a id=word'+idcount+' style="cursor:pointer" onclick="getDetail(this);">'+unpassli[i]+'</a>'+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>';
					idcount++;
				}
				$("#unpass").html(htmlAppend);
			}
			if(unchecked.length>2){
				//alert(unchecked);
				unchecked=unchecked.substring(1,unchecked.length-1);
				var unchecli =unchecked.split(",");
				var htmlAppend='';
				//var displaycount=20;//展示20个即可
				//if(unchecli.length<20){displaycount=unchecli.length}
				var displaycount5=unchecli.length;
				for(var i=0;i<displaycount5;i++){
					//alert(unchecli[i]);
					htmlAppend=htmlAppend+'&nbsp;&nbsp;&nbsp;<a id=word'+idcount+' style="cursor:pointer" onclick="getDetail(this);">'+unchecli[i]+'</a>'+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>';
					idcount++;
				}
				$("#uncheck").html(htmlAppend);
			}
		});
	}
});


function getDetail(elem){
	var chinese=$(elem).html().trim();//记得去掉空格~
	chinese=chinese.replace(/&nbsp;/g,"");//记住这个写法：/要被替换的内容/g
	//alert(chinese);
	 //以防词重复，把编撰者的姓名也传过去.
	var compiler=$("input[id='worker2']").val();
	//alert(compiler);
	
	$.post('jsp/worddictionary/getWord.jsp', 'chinese='+chinese+'&compiler='+compiler, function(data) {
        //alert("bb");
		json = eval('('+data+')');//第一次解析
		var res=json.wordjson;
		
		json = eval('('+res+')');//第二次解析
		//var number=json.number;
		//alert(number);
		$("#chosenWords").text(json.chinese);
		$("#term-subject").val(json.subject);
		$("#id_term").val(json.number);
		$("#term-chi").val(json.chinese);
		$("#word-class").val(json.cixing);
		$("#recommendName").val(json.formalword);
		$("#recommendTrans").val(json.formaltranslation);
		$("#term-eng1").val(json.english1);
		$("#term-frequen1").val(json.frequence1);
		$("#chi_context1").val(json.chincondition1);
		$("#eng_context1").val(json.engcondition1);
		$("#term-eng2").val(json.english2);
		$("#term-frequen2").val(json.frequence2);
		$("#chi_context2").val(json.chincondition2);
		$("#eng_context2").val(json.engcondition2);
		$("#term-eng3").val(json.english3);
		$("#term-frequen3").val(json.frequence3);
		$("#chi_context3").val(json.chincondition3);
		$("#eng_context3").val(json.engcondition3);
		$("#term-eng4").val(json.english4);
		$("#term-frequen4").val(json.frequence4);
		$("#chi_context4").val(json.chincondition4);
		$("#eng_context4").val(json.engcondition4);
		$("#term-eng5").val(json.english5);
		$("#term-frequen5").val(json.frequence5);
		$("#chi_context5").val(json.chincondition5);
		$("#eng_context5").val(json.engcondition5);
		$("#cizu1").val(json.cizu1);
		$("#translation1").val(json.translation1);
		$("#cizu2").val(json.cizu2);
		$("#translation2").val(json.translation2);
		$("#cizu3").val(json.cizu3);
		$("#translation3").val(json.translation3);
		$("#cizu4").val(json.cizu4);
		$("#translation4").val(json.translation4);
		$("#cizu5").val(json.cizu5);
		$("#translation5").val(json.translation5);
		$("#synonym1").val(json.synonym1);
		$("#synonym2").val(json.synonym2);
		$("#synonym3").val(json.synonym3);
		$("#synonym4").val(json.synonym4);
		$("#synonym5").val(json.synonym5);
		$("#antonym1").val(json.antonym1);
		$("#antonym2").val(json.antonym2);
		$("#antonym3").val(json.antonym3);
		$("#antonym4").val(json.antonym4);
		$("#antonym5").val(json.antonym5);
		$("#related").val(json.linkword);
		$("#personInCharge").val(json.compiler);
		$("#insertdate").val(json.date);
		$("#term_situation").val(json.status);
		$("#is_pass").val(json.ispass);
		$("#updateRemark").val(json.advice);
		$("#updatedate").val(json.renewdate);
	});
};

$("#save_edit").click(function(){
	//alert("kk");
	var chinese=$("#chosenWords").text();
	var ispass=$("#is_pass").val();
	var renewdate=$("#updatedate").val();
	var advice=$("#updateRemark").val();
	//alert(chinese+ispass+renewdate+advice);
	$.post('jsp/worddictionary/updateWordManage.jsp', 'chinese='+chinese+'&ispass='+ispass+'&renewdate='+renewdate+'&advice='+advice, function(data) {
        //alert("bb");
		json = eval('('+data+')');//第一次解析
		var res=json.result;
		//alert(res);
		if(res=="success"){
			alert("保存成功!");
			$('#searchbtn2').click();
		}else{
			alert("保存失败!请重新保存！若多次无法保存，请联系管理员！");
		}
		
		
	});
});



